package com.ibm.demo_hibernate_2;


import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;


import Data.TblMoto;

import Ulti.DBUlti;

public class motoDAO {
	PreparedStatement pstmt;
	ResultSet rs;
	Connection con = DBUlti.openConnection();
	public motoDAO() {
		// TODO Auto-generated constructor stub
		
	}
	public List<TblMoto> getListMoto() {
		List<TblMoto> list = new ArrayList<TblMoto>();
		try {
			pstmt = con.prepareStatement("select * from TBL_MOTO");
			rs = pstmt.executeQuery();
			while(rs.next()){
				TblMoto xe = new TblMoto();
//				"ID" NUMBER(19,0) NOT NULL ENABLE, 
				xe.setId(rs.getBigDecimal("ID"));
//				"SO_MAY" VARCHAR2(255 BYTE) NOT NULL ENABLE, 
				xe.setSoMay(rs.getString("SO_MAY"));
//				"SO_KHUNG" VARCHAR2(255 BYTE) NOT NULL ENABLE, 
				xe.setSoKhung(rs.getString("SO_KHUNG"));
//				"NUOC_SAN_XUAT" NUMBER(10,0), 
				xe.setNuocSanXuat(rs.getLong("NUOC_SAN_XUAT"));
//				"NAM_SAN_XUAT" NUMBER(4,0), 
				xe.setNamSanXuat(rs.getShort("NAM_SAN_XUAT"));
//				"DUNG_TICH" NUMBER(6,0), 
				xe.setDungTich(rs.getInt("DUNG_TICH"));
//				"CONG_XUAT" NUMBER(10,0),
				xe.setCongXuat(rs.getLong("CONG_XUAT"));
//				"NIEN_HAN_SU_DUNG" DATE, 
				xe.setNienHanSuDung(rs.getDate("NIEN_HAN_SU_DUNG"));
//				"SONGUOI_DUOCPHEPCHO" NUMBER(1,0), 
				xe.setSonguoiDuocphepcho(rs.getByte("SONGUOI_DUOCPHEPCHO"));
//				"HINH_ANH" BLOB, 
				xe.setHinhAnh(rs.getBlob("HINH_ANH"));
//				"NGUON_GOC" VARCHAR2(30 BYTE), 
				xe.setNguonGoc(rs.getString("NGUON_GOC"));
//				"SO_CHUNG_TU" VARCHAR2(10 BYTE), 
				xe.setSoChungTu(rs.getString("SO_CHUNG_TU"));
//				"NGAYCAP_CHUNGTU" DATE, 
				xe.setNgaycapChungtu(rs.getDate("NGAYCAP_CHUNGTU"));
//				"COQUAN_CAPCHUNGTU" VARCHAR2(50 BYTE), 
				xe.setCoquanCapchungtu(rs.getString("COQUAN_CAPCHUNGTU"));
//				"LOAI_NHIEN_LIEU" VARCHAR2(30 BYTE), 
				xe.setLoaiNhienLieu(rs.getString("LOAI_NHIEN_LIEU"));
//				"MAU_XE" VARCHAR2(30 BYTE), 
				xe.setMauXe(rs.getString("MAU_XE"));
//				"NGUOI_TAO" NUMBER(10,0) NOT NULL ENABLE, 
				xe.setNguoiTao(rs.getInt("NGUOI_TAO"));
//				"NGAY_TAO" DATE NOT NULL ENABLE, 
				xe.setNgayTao(rs.getDate("NGAY_TAO"));
//				"NGUOI_SUA" NUMBER(10,0), 
				xe.setNguoiSua(rs.getLong("NGUOI_SUA"));
//				"NGAY_SUA" DATE, 
				xe.setNgaySua(rs.getDate("NGAY_SUA"));
//				"TRANG_THAI" VARCHAR2(30 BYTE), 
				xe.setTrangThai(rs.getString("TRANG_THAI"));
//				"NOI_BAO" VARCHAR2(50 BYTE), 
				xe.setNoiBao(rs.getString("NOI_BAO"));
//				"NGAY_BAO" DATE, 
				xe.setNgayBao(rs.getDate("NGAY_BAO"));
//				"GHICHU" VARCHAR2(255 BYTE), 
				xe.setGhichu(rs.getString("GHICHU"));
//				"NHANHIEU_LOAIXE_ID" NUMBER(10,0) NOT NULL ENABLE,
				xe.setNhanhieuLoaixeId(rs.getInt("NHANHIEU_LOAIXE_ID"));
//				"PHIEN_BAN" VARCHAR2(10 BYTE), 
				xe.setPhienBan(rs.getString("PHIEN_BAN"));
				list.add(xe);
			}
		}
		catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	public TblMoto getMotobyID(BigDecimal id){
		TblMoto xe = null;
		try {
			pstmt = con.prepareStatement("select * from TBL_MOTO where id = ?");
			pstmt.setBigDecimal(1, id);
			rs = pstmt.executeQuery();
			if(rs.next()){
				xe = new TblMoto();
//				"ID" NUMBER(19,0) NOT NULL ENABLE, 
				xe.setId(rs.getBigDecimal("ID"));
//				"SO_MAY" VARCHAR2(255 BYTE) NOT NULL ENABLE, 
				xe.setSoMay(rs.getString("SO_MAY"));
//				"SO_KHUNG" VARCHAR2(255 BYTE) NOT NULL ENABLE, 
				xe.setSoKhung(rs.getString("SO_KHUNG"));
//				"NUOC_SAN_XUAT" NUMBER(10,0), 
				xe.setNuocSanXuat(rs.getLong("NUOC_SAN_XUAT"));
//				"NAM_SAN_XUAT" NUMBER(4,0), 
				xe.setNamSanXuat(rs.getShort("NAM_SAN_XUAT"));
//				"DUNG_TICH" NUMBER(6,0), 
				xe.setDungTich(rs.getInt("DUNG_TICH"));
//				"CONG_XUAT" NUMBER(10,0),
				xe.setCongXuat(rs.getLong("CONG_XUAT"));
//				"NIEN_HAN_SU_DUNG" DATE, 
				xe.setNienHanSuDung(rs.getDate("NIEN_HAN_SU_DUNG"));
//				"SONGUOI_DUOCPHEPCHO" NUMBER(1,0), 
				xe.setSonguoiDuocphepcho(rs.getByte("SONGUOI_DUOCPHEPCHO"));
//				"HINH_ANH" BLOB, 
				xe.setHinhAnh(rs.getBlob("HINH_ANH"));
//				"NGUON_GOC" VARCHAR2(30 BYTE), 
				xe.setNguonGoc(rs.getString("NGUON_GOC"));
//				"SO_CHUNG_TU" VARCHAR2(10 BYTE), 
				xe.setSoChungTu(rs.getString("SO_CHUNG_TU"));
//				"NGAYCAP_CHUNGTU" DATE, 
				xe.setNgaycapChungtu(rs.getDate("NGAYCAP_CHUNGTU"));
//				"COQUAN_CAPCHUNGTU" VARCHAR2(50 BYTE), 
				xe.setCoquanCapchungtu(rs.getString("COQUAN_CAPCHUNGTU"));
//				"LOAI_NHIEN_LIEU" VARCHAR2(30 BYTE), 
				xe.setLoaiNhienLieu(rs.getString("LOAI_NHIEN_LIEU"));
//				"MAU_XE" VARCHAR2(30 BYTE), 
				xe.setMauXe(rs.getString("MAU_XE"));
//				"NGUOI_TAO" NUMBER(10,0) NOT NULL ENABLE, 
				xe.setNguoiTao(rs.getInt("NGUOI_TAO"));
//				"NGAY_TAO" DATE NOT NULL ENABLE, 
				xe.setNgayTao(rs.getDate("NGAY_TAO"));
//				"NGUOI_SUA" NUMBER(10,0), 
				xe.setNguoiSua(rs.getLong("NGUOI_SUA"));
//				"NGAY_SUA" DATE, 
				xe.setNgaySua(rs.getDate("NGAY_SUA"));
//				"TRANG_THAI" VARCHAR2(30 BYTE), 
				xe.setTrangThai(rs.getString("TRANG_THAI"));
//				"NOI_BAO" VARCHAR2(50 BYTE), 
				xe.setNoiBao(rs.getString("NOI_BAO"));
//				"NGAY_BAO" DATE, 
				xe.setNgayBao(rs.getDate("NGAY_BAO"));
//				"GHICHU" VARCHAR2(255 BYTE), 
				xe.setGhichu(rs.getString("GHICHU"));
//				"NHANHIEU_LOAIXE_ID" NUMBER(10,0) NOT NULL ENABLE,
				xe.setNhanhieuLoaixeId(rs.getInt("NHANHIEU_LOAIXE_ID"));
//				"PHIEN_BAN" VARCHAR2(10 BYTE), 
				xe.setPhienBan(rs.getString("PHIEN_BAN"));
			}
		}
		catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return xe;
	}
		
	

}
